package com.bdqn.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * LoginController
 *
 * @author
 * @since 2021-11-29
 */
@Controller
public class LoginController {

    @Resource
    private SysUserService sysUserService;

    @GetMapping("/main")
    public String main() {
        return "main";
    }

    @RequestMapping("/login")
    public String login(HttpSession session, String usrName, String usrPassword) {
        System.out.println("/login ----------------------");
        QueryWrapper<SysUser> qw = new QueryWrapper<>();
        qw.eq("usr_name", usrName);
        SysUser sysUser = sysUserService.getOne(qw);
        if (sysUser != null) {
            System.out.println("登录成功！----------------------");
            session.setAttribute("loginUser", sysUser);
        }
        return "main";
    }
}
